package zuk.clipvuiviet;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

public class ApiYoutube extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener, OnEditorActionListener {
	private YouTubePlayerView ytpv;
	String title;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.youtube);
		ytpv = (YouTubePlayerView) findViewById(R.id.youtubeplayer);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//		ytpv.initialize("AIzaSyC_4OmQ6fX8kObeviR1jKYv-ugpJePx4QE", this);
		ytpv.initialize("AIzaSyBEu5A-veKthrsdzhuf1DvY32vwcpxoJOA", this);
		Bundle extras = getIntent().getExtras();
		title = extras.getString("key");

	}

	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		return false;
	}

	@Override
	public void onInitializationFailure(Provider arg0,YouTubeInitializationResult arg1) {
		Toast.makeText(this, "Initialization Fail, Update latest version of youtube!!", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,boolean arg2) {
		if (!arg2) {
//			Toast.makeText(this, "Initialization  Success", Toast.LENGTH_LONG).show();
			arg1.loadVideo(title);
		}
	}

}
